package top.humbleyuan.test.Huawei;

import java.util.*;

/**
 * @Author HumbleYuan
 * @Date 2020/4/22 18:42
 * @Des
 */
public class Huawei_422 {
    public static void main(String[] args) {
        //m1();

        e2();

        //e3();
    }

    private static void e3() {
        Scanner sc = new Scanner(System.in);

        String[] first = sc.nextLine().split(" ");
        int m = Integer.valueOf(first[0]);
        int n = Integer.valueOf(first[1]);

        int[] nums = new int[m];
        for (int i = 0; i < m; i++) {
            nums[i] = sc.nextInt();
        }

        Arrays.sort(nums);

        //ArrayList<int[]> res = dfs(nums, 0, new ArrayList<>());

        sc.close();
    }

    public static void dfs(int[] nums, int curMax, ArrayList<int[]> list, int n, int curIndex, int[] curQ) {
        if(list.size() == n - 1) {
            if(curIndex < nums.length - 1) {
                list.add(Arrays.copyOfRange(nums, curIndex, nums.length));
                return;
            }
        }


        for (int i = 0; i < nums.length - n; i++) {

        }
    }

    private static void e2() {
        Scanner sc = new Scanner(System.in);

        String[] data = sc.nextLine().split(" ");

        int i = 0;
        while (!data[i].equals("5a") && i < data.length) {
            i++;
        }

        String s = "";
        ArrayList<String> list = new ArrayList<>();
        while (i < data.length) {

            if(data[i].equals("5a")) {
                list.add(s);
                s = "";
                continue;
            }
            s += data[i] + " ";
            i++;
        }

        if(list.size() == 0) {
            System.out.println("");
        }
        String res = "";

        // 验证每一个
        for (int j = 0; j < list.size(); j++) {
            int size = 0;
            String[] s1 = list.get(j).split(" ");

            for (int m = 0; i < s1.length - 1; m++) {
               size += 2;
               if(s1[m].equals("5b") && m < s1.length - 2) {
                   if(s1[m + 1].equals("bb") || s1[m + 1].equals("ba")) {
                       m += 2;
                   }
               }
            }

            if(Integer.valueOf(s1[s1.length - 1]) != size) {
                list.remove(j--);
            }
        }

        for (int j = 0; j < list.size(); j++) {
            res += "5a ";
            String[] s1 = list.get(j).split(" ");
            for (int m = 0; m < s1.length; m++) {
                res += s1[m] + " ";
            }
            res += "5a";
        }

        System.out.println(res);


        sc.close();
    }

    private static void m1() {
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();
        if(s == null) {
            System.out.println("");
            return;
        }

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) >= '0' && s.charAt(i) <= '9') {
                list.add(s.charAt(i) - '0');
            }
        }
        Collections.sort(list);
        String res = "";
        for (int i = 0; i < list.size(); i++) {
            res += list.get(i);
        }

        System.out.println(res);

        sc.close();
    }
}
